#include <time.h>

#define BENCHMARK_FUNC(warmup, iters, func, ...)                                              \
    do                                                                                        \
    {                                                                                         \
        struct timespec __start, __end;                                                       \
        double __total = 0;                                                                   \
        for (int __i = 0; __i < (warmup); ++__i)                                              \
        {                                                                                     \
            func(__VA_ARGS__);                                                                \
        }                                                                                     \
        clock_gettime(CLOCK_MONOTONIC, &__start);                                             \
        for (int __i = 0; __i < (iters); ++__i)                                               \
        {                                                                                     \
            func(__VA_ARGS__);                                                                \
        }                                                                                     \
        clock_gettime(CLOCK_MONOTONIC, &__end);                                               \
        __total += (__end.tv_sec - __start.tv_sec) * 1e9 + (__end.tv_nsec - __start.tv_nsec); \
        printf("函数%s耗时: %.2f ns\n", #func, __total / iters);                              \
    } while (0)